﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Xml.Linq;
using Colorful.Furniture.CommonDto;
using Colorful.Furniture.Enum;
using Colorful.Furniture.Extensions;
using Newtonsoft.Json;

namespace Colorful.Furniture.ErpInventoryManagement;

/// <summary>
///  库存分页请求体
/// </summary>
public class InventoryPagedInputDto : PageInputDto
{
    /// <summary>
    ///  类别
    /// </summary>
    public int? Type { get; set; }

    /// <summary>
    ///  产品名称
    /// </summary>
    public string Product { get; set; }

    /// <summary>
    ///  供应商名称
    /// </summary>
    public string SupplierName { get; set; }

    /// <summary>
    ///  客户名称
    /// </summary>
    public string CustomerName { get; set; }

    /// <summary>
    ///  产品类型
    /// </summary>
    public ProductType? ProductType { get; set; }

    /// <summary>
    ///  类别
    /// </summary>
    public Guid? CategoryId { get; set; }

    /// <summary>
    ///  状态（0 = 禁用，1 = 启用，2 = 下架，3 = 上架）
    /// </summary>
    public int? Status { get; set; }

    /// <summary>
    ///  是否为测试商品（0 = 否；1 = 是；）
    /// </summary>
    public int? IsTest { get; set; }


}

//库存产品日志
public class InventoryLogPagedInputDto : PageInputDto
{
    /// <summary>
    ///  库存产品表示
    /// </summary>
    public Guid InventoryId { get; set; }
}

/// <summary>
///  库存产品数据添加
/// </summary>
public class InventorySaveInputDto
{
    /// <summary>
    ///  编码
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    ///  图册
    /// </summary>
    public List<FileStandardDto> AlbumList { get; set; }

    /// <summary>
    ///  图册，方便客户进行区分
    /// </summary>
    [JsonIgnore]
    public string Album => AlbumList.GenericToString();

    /// <summary>
    ///  封面图片
    /// </summary>
    public string CoverImg => AlbumList.Any() ? AlbumList.First().Url : string.Empty;

    /// <summary>
    ///  产品类型
    /// </summary>
    public ProductType? ProductType { get; set; }

    /// <summary>
    ///  产品编号 
    /// </summary>
    public string ProductNo { get; set; }

    /// <summary>
    ///   产品名字
    /// </summary>
    [Required(ErrorMessage = "请输入产品名字")]
    public string ProductName { get; set; }

    /// <summary>
    ///  分类
    /// </summary>
    public string Category { get; set; }

    /// <summary>
    ///  分类编码
    /// </summary>
    public Guid? CategoryId { get; set; }

    /// <summary>
    ///  产品规则
    /// </summary>
    public string Rules { get; set; }

    /// <summary>
    /// 是否为测试商品（0 = 否；1 = 是；）
    /// </summary>
    public int? IsTestOrder { get; set; }

    /// <summary>
    ///  京东SKU
    /// </summary>
    public string JdSku { get; set; }

    /// <summary>
    ///  是否验证邮箱：1 = 是；0 = 否；
    /// </summary>
    public int? IsCheckEmail { get; set; }

    ///// <summary>
    /////  金额
    ///// </summary>
    //[RegularExpression(RegexSet.UnitPriceRegex, ErrorMessage = "请输入正确的成本价")]
    //public string Price { get; set; }
}


/// <summary>
///  产品保存
/// </summary>
public class InventoryRawInputDto
{

    /// <summary>
    ///   产品名字
    /// </summary>
    public string ProductName { get; set; }

    /// <summary>
    ///  面额
    /// </summary>
    public string FaceRemark { get; set; }

    /// <summary>
    /// 面值
    /// </summary>
    public int? FaceAmount { get; set; }

}

/// <summary>
/// 商品配置信息输入体
/// </summary>
public class InventoryDetailSaveInputDto
{

    /// <summary>
    ///  id
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    ///  备案信息 
    /// </summary>
    public string Filings { get; set; }

    /// <summary>
    /// 是否跳转其余推广页：0=不跳转；1=跳转；
    /// </summary>
    public int? IsJumpOther { get; set; }

    /// <summary>
    /// 是否二次确认：0=不需要；1=需要；
    /// </summary>
    public int? IsConfirm { get; set; }
    
    /// <summary>
    ///  输入框背景图
    /// </summary>
    public string BackgroundImg { get; set; }

    /// <summary>
    ///  输入框背景图数组
    /// </summary>
    public List<FileStandardDto> BackgroundImgList { get; set; }

    /// <summary>
    ///  封面图片-图册
    /// </summary>
    [JsonIgnore]
    public string CoverImg => CoverImgList.GenericToString();

    /// <summary>
    ///  封面图片列表
    /// </summary>
    public List<FileStandardDto> CoverImgList { set; get; }

    /// <summary>
    ///  商品内容图片-图册
    /// </summary>
    [JsonIgnore]
    public string Content => ContentList.GenericToString();

    /// <summary>
    ///  商品内容图片列表
    /// </summary>
    public List<FileStandardDto> ContentList { set; get; }

    /// <summary>
    ///  二次确认背景图
    /// </summary>
    public string SecondPopImg { get; set; }

    /// <summary>
    ///  二次确认背景图
    /// </summary>
    public List<FileStandardDto> SecondPopImgList { get; set; }

}


/// <summary>
///  产品保存
/// </summary>
public class InventoryRawSaveInputDto
{
    /// <summary>
    ///  编码
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    ///  图册
    /// </summary>
    public List<FileStandardDto> AlbumList { get; set; }

    /// <summary>
    ///  图册，方便客户进行区分
    /// </summary>
    [JsonIgnore]
    public string Album => AlbumList.GenericToString();

    ///// <summary>
    /////  封面图片
    ///// </summary>
    //public string CoverImg => AlbumList.Any() ? AlbumList.First().Url : string.Empty;

    /// <summary>
    ///  产品类型
    /// </summary>
    public ProductType? ProductType { get; set; }

    /// <summary>
    ///  产品编号 
    /// </summary>
    public string ProductNo { get; set; }

    /// <summary>
    ///   产品名字
    /// </summary>
    [Required(ErrorMessage = "请输入产品名字")]
    public string ProductName { get; set; }

    /// <summary>
    ///  分类
    /// </summary>
    public string Category { get; set; }

    /// <summary>
    ///  分类编码
    /// </summary>
    public Guid? CategoryId { get; set; }

    /// <summary>
    ///  面额
    /// </summary>
    [Required(ErrorMessage = "请输入面额")]
    public string FaceRemark { get; set; }

    /// <summary>
    /// 面值
    /// </summary>
    [Required(ErrorMessage = "请输入面值")]
    public decimal? FaceAmount { get; set; }

    /// <summary>
    ///  京东SKU
    /// </summary>
    public string JdSku { get; set; }

    /// <summary>
    ///  产品规则
    /// </summary>
    public string Rules { get; set; }

    /// <summary>
    ///  备注
    /// </summary>
    public string Remark { get; set; }

    /// <summary>
    ///  是否为测试商品（0 = 否；1 = 是；）
    /// </summary>
    public int? IsTest { get; set; }

    /// <summary>
    ///  是否验证邮箱：1 = 是；0 = 否；
    /// </summary>
    public int? IsCheckEmail { get; set; }

    /// <summary>
    ///  供应商名称合集
    /// </summary>
    public string SupplierName { get; set; }

    /// <summary>
    ///  供应商产品编号合集
    /// </summary>
    public string SupplierProductCode { get; set; }

    /// <summary>
    ///  排序字段：值越大越靠前
    /// </summary>
    public int Sort { get; set; }

    /// <summary>
    ///  推广地址 
    /// </summary>
    public string Link { get; set; }

    /// <summary>
    ///  参考链接地址 
    /// </summary>
    public string ReferenceLink { get; set; }

    /// <summary>
    ///  sku集合
    /// </summary>
    public List<InventorySkuInputDto> InventorySkus { get; set; }


}

/// <summary>
///  库存产品sku请求体
/// </summary>
public class InventorySkuInputDto
{
    /// <summary>
    ///   编码
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    ///  排序
    /// </summary>
    [RegularExpression(RegexSet.IntegerRegex, ErrorMessage = "供应商排序不能为空")]
    public int? Sort { get; set; }

    /// <summary>
    ///  供应商标识
    /// </summary>
    public Guid? SupplierId { get; set; }

    /// <summary>
    ///  供应商产品名称
    /// </summary>
    public string SupplierProductName { get; set; }

    /// <summary>
    ///  供应商产品编号
    /// </summary>
    public string SupplierProductNo { get; set; }

    /// <summary>
    ///  供应商成本总价
    /// </summary>
    [RegularExpression(RegexSet.UnitPriceRegex, ErrorMessage = "请输入正确的供应商成本总价")]
    public decimal? CostPrice { get; set; }

    /// <summary>
    ///  供应商成本单价
    /// </summary>
    [RegularExpression(RegexSet.UnitPriceRegex, ErrorMessage = "请输入正确的供应商成本单价")]
    public decimal? CostUnitPrice { get; set; }

    /// <summary>
    ///  是否启用
    /// </summary>
    public int? IsEnable { get; set; }

    /// <summary>
    ///  换算比例：1个客户订单数量 = * 个供应商订单数量
    /// </summary>
    public int? SupplierQty { get; set; }

    /// <summary>
    ///  下游最大提交数量
    /// </summary>
    public int? MaxQty { get; set; }

    /// <summary>
    ///  下游最小提交数量
    /// </summary>
    public int? MinQty { get; set; }

    /// <summary>
    ///  帐号所属类型
    /// </summary>
    public string AcctType { get; set; }

    /// <summary>
    ///  折扣
    /// </summary>
    public decimal? Discount { get; set; }

}

/// <summary>
/// 产品状态输入体
/// </summary>
public class InventoryStatesInputDto
{
    /// <summary>
    /// 产品id
    /// </summary>
    public List<Guid?> Id { get; set; }

    /// <summary>
    ///  产品状态（0 = 禁用，1 = 启用，2 = 下架，3 = 上架）
    /// </summary>

    public int StateType { get; set; }
}

/// <summary>
///  产品关联客户保存
/// </summary>
public class InventoryWithCustomerSaveInputDto
{
    /// <summary>
    ///  编码
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    ///  产品编号
    /// </summary>
    public string ProductNo { get; set; }

    /// <summary>
    ///  客户集合
    /// </summary>
    public List<InventoryWithCustomerInputDto> InventoryWithCustomers { get; set; }

}

/// <summary>
///  产品关联客户请求体
/// </summary>
public class InventoryWithCustomerInputDto
{
    /// <summary>
    ///   编码
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    ///   产品编码
    /// </summary>
    public Guid? InventoryId { get; set; }

    /// <summary>
    ///  产品编号
    /// </summary>
    public string ProductNo { get; set; }

    /// <summary>
    ///  客户编码
    /// </summary>
    public Guid? CustomerId { get; set; }

    /// <summary>
    ///  折扣
    /// </summary>
    public decimal? Discount { get; set; }

    /// <summary>
    ///  售价
    /// </summary>
    public decimal? SalePrice { get; set; }

    /// <summary>
    ///  手续费
    /// </summary>
    public decimal? Commission { get; set; }

}

/// <summary>
///  产品关联SkuNew请求体
/// </summary>
public class InventoryShopInputDto
{

    /// <summary>
    ///   编码
    /// </summary>
    public Guid Id { get; set; }

    /// <summary>
    ///   产品编码
    /// </summary>
    public Guid? InventoryId { get; set; }

    /// <summary>
    ///  产品编号
    /// </summary>
    public string ProductNo { get; set; }

    /// <summary>
    ///  抖音商品编码
    /// </summary>
    public string SupplierProductNo { get; set; }

    /// <summary>
    /// 抖音商品的skuId
    /// </summary>
    public string SkuId { get; set; }

    /// <summary>
    ///  提交订单时刻的商品数量换算比例（1：Number）
    /// </summary>
    public int? Number { get; set; }

}

/// <summary>
///  产品Sku保存
/// </summary>
public class InventoryShopSaveInputDto
{
    /// <summary>
    ///  编码
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    ///  产品编号
    /// </summary>
    public string ProductNo { get; set; }

    /// <summary>
    ///  客户集合
    /// </summary>
    public List<InventoryShopInputDto> InventoryShops { get; set; }

}
